// Author: wsfuyibing <682805@qq.com>
// Date: 2025-04-28

package kind

// DiscountType
// 折扣类型.
type DiscountType int

const (
	_ DiscountType = iota

	DiscountTypeFixed   // 固定减免
	DiscountTypePercent // 比例打折
)

var (
	discountTypeTexts = map[DiscountType]string{
		DiscountTypeFixed:   "固定减免",
		DiscountTypePercent: "比例打折",
	}
	discountTypeUnknownText = "未知"

	discountTypeFlags = map[DiscountType]string{
		DiscountTypeFixed:   "fixed",
		DiscountTypePercent: "percent",
	}
	discountTypeUnknownFlag = "unknown"
)

func DiscountTypeDict() []map[string]any {
	var res = make([]map[string]any, 0)
	for _, v := range []DiscountType{
		DiscountTypeFixed,
		DiscountTypePercent,
	} {
		res = append(res, map[string]any{
			"Key":   v,
			"Value": v.Text(),
		})
	}
	return res
}

func (o DiscountType) Flag() string {
	if str, ok := discountTypeFlags[o]; ok {
		return str
	}
	return discountTypeUnknownFlag
}

func (o DiscountType) IsFixed() bool   { return o == DiscountTypeFixed }
func (o DiscountType) IsPercent() bool { return o == DiscountTypePercent }

func (o DiscountType) Text() string {
	if str, ok := discountTypeTexts[o]; ok {
		return str
	}
	return discountTypeUnknownText
}
